﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Editor.PageControls;

namespace Editor.Main_Windows
{
    public partial class ControlList : Form
    {
        public ControlList()
        {
            InitializeComponent();
        }

        private void ControlList_FormClosed(object sender, FormClosedEventArgs e)
        {
            EditorForm.ControlListChecked = false;
        }

        private void ControlList_Load(object sender, EventArgs e)
        {
            UpdateList();
        }

        public void UpdateList()
        {
            listBoxControls.Items.Clear();
            listBoxControls.Items.AddRange(EditorForm.CurrentPage.Controls.ToArray());
        }

        private void listBoxControls_MouseUp(object sender, MouseEventArgs e)
        {
            int index = listBoxControls.IndexFromPoint(e.Location);

            if (index >= 0)
            {
                listBoxControls.SelectedItem = listBoxControls.Items[index];

                if (e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    (listBoxControls.SelectedItem as PageControl).Select();
                }
            }
            else
                listBoxControls.SelectedItem = null;
        }
    }
}
